#!/bin/bash
LIST_FILE=~/src/jumpHost/list
IPS=$(ifconfig |grep inet[^6]|grep broadcast|awk '{print $2,$4}')
IP=$(echo $IPS|awk '{print $1}')
MASK=$(ipcalc -p $IPS|awk -F= '{print $2}')

if [ "$1" != "now" ]
then
	nmap -sn ${IP}/${MASK}|grep report>$LIST_FILE
fi

MIN_INDEX=1
MAX_INDEX=$(wc -l $LIST_FILE|awk '{print $1}')

awk '{name[NR]=$5;ip[NR]=$6}END{for(i=1;i<=NR;i++){print i,name[i],ip[i]}}' $LIST_FILE
echo "input Num: "
read index
if [ $index -lt $MIN_INDEX ]
then 
	exit 2
elif [ $index -gt $MAX_INDEX ]
then
	exit 2
fi
JUMP_HOST=$(awk '{print $5}' $LIST_FILE|sed -n "${index}p")
echo "ssh $JUMP_HOST..."
ssh $JUMP_HOST
